package cn.tedu.hotelApi.dictOption.service.impl;

import cn.tedu.hotelApi.dictOption.mapper.DictOptionMapper;
import cn.tedu.hotelApi.dictOption.pojo.dto.DictOptionParam;
import cn.tedu.hotelApi.dictOption.pojo.dto.DictOptionQuery;
import cn.tedu.hotelApi.dictOption.pojo.entity.DictOption;
import cn.tedu.hotelApi.dictOption.pojo.vo.DictOptionVO;
import cn.tedu.hotelApi.dictOption.service.DictOptionService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DicOptionServiceImpl implements DictOptionService {
    @Autowired
    private DictOptionMapper dictOptionMapper;
    @Override
    public List<DictOptionVO> selectDictOption(DictOptionQuery dictOptionQuery) {
        List<DictOptionVO> dictOptionVOList = dictOptionMapper.select(dictOptionQuery);
        return dictOptionVOList;
    }

    @Override
    public void saveDictOption(DictOptionParam dictOptionParam) {
        DictOption dictOption = new DictOption();
        BeanUtils.copyProperties(dictOptionParam, dictOption);
        dictOption.setCreateTime(new Date());
        if (dictOption.getId() != null){
            dictOptionMapper.update(dictOption);
        }else {
            dictOptionMapper.insert(dictOption);
        }
    }

    @Override
    public void deleteDictOption(Long id) {
        dictOptionMapper.delete(id);
    }
}
